package com.leyou.auth.feign;

import com.leyou.auth.config.JwtProperties;
import com.leyou.auth.task.AppTokenHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PrivilegeInterceptor implements RequestInterceptor {
    @Autowired
    private JwtProperties jwtProperties;

    @Autowired
    private AppTokenHolder tokenHolder;

    @Override
    public void apply(RequestTemplate requestTemplate) {
        // 获取token
        String token = tokenHolder.getToken();
        // 给请求头添加信息
        requestTemplate.header(jwtProperties.getApp().getHeaderName(), token);
    }
}
